package view;

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;

public class Util {

	/**
	 * Returns an image capable of Transparency with the specified
	 * size.
	 * 
	 * @param width
	 * @param height
	 * @return
	 */
	public static Image createImageBuffer(int width, int height) {
		if (width <= 0 || height <= 0) return (null);
		BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
		return (img);
	}
	
	public static VolatileImage createVolatileBuffer(int width, int height) {
		if (width <= 0 || height <= 0) return (null);
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
		
		VolatileImage image = null;
		
		image = gc.createCompatibleVolatileImage(width, height, Transparency.TRANSLUCENT);
		int valid = image.validate(gc);
		
		if (valid == VolatileImage.IMAGE_INCOMPATIBLE) {
			image = createVolatileBuffer(width, height);
			return (image);
		}
		
		return (image);
	}
}
